package com.ruoyi.web.controller.parts;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.CollectionUtils;
import com.ruoyi.system.domain.ProductType;
import com.ruoyi.system.domain.vo.carInfo.CarDictVo;
import com.ruoyi.system.domain.vo.carInfo.CarInfoListVo;
import com.ruoyi.system.domain.vo.productInfo.ProductDictVo;
import com.ruoyi.system.domain.vo.productInfo.ProductInfoListVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarInfo;
import com.ruoyi.system.service.ICarInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汽车信息Controller
 *
 * @author ruoyi
 * @date 2023-01-25
 */
@RestController
@RequestMapping("/parts/carInfo")
public class CarInfoController extends BaseController
{
    @Autowired
    private ICarInfoService carInfoService;

    /**
     * 查询汽车信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:carinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarInfo carInfo)
    {
        startPage();
        List<CarInfo> list = carInfoService.selectCarInfoList(carInfo);
        TableDataInfo dataTable = getDataTable(list);
        List<?> rows = dataTable.getRows();
        List<CarInfoListVo> voList = CollectionUtils.convertCollectionType(rows, CarInfoListVo.class);
        dataTable.setRows(voList);
        return dataTable;
    }

    /**
     * 查询汽车信息列表,dict
     */
    @PreAuthorize("@ss.hasPermi('system:carinfo:list')")
    @GetMapping("/getCarDict")
    public TableDataInfo getCarDict(CarInfo carInfo)
    {
        //        startPage();
        List<CarDictVo> list = carInfoService.selectCarDict(carInfo);
        return getDataTable(list);
    }

    /**
     * 导出汽车信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:carinfo:export')")
    @Log(title = "汽车信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarInfo carInfo)
    {
        List<CarInfo> list = carInfoService.selectCarInfoList(carInfo);
        ExcelUtil<CarInfo> util = new ExcelUtil<CarInfo>(CarInfo.class);
        util.exportExcel(response, list, "汽车信息数据");
    }

    /**
     * 获取汽车信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:carinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carInfoService.selectCarInfoById(id));
    }

    /**
     * 新增汽车信息
     */
    @PreAuthorize("@ss.hasPermi('system:carinfo:add')")
    @Log(title = "汽车信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarInfo carInfo)
    {
        return toAjax(carInfoService.insertCarInfo(carInfo));
    }

    /**
     * 修改汽车信息
     */
    @PreAuthorize("@ss.hasPermi('system:carinfo:edit')")
    @Log(title = "汽车信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarInfo carInfo)
    {
        return toAjax(carInfoService.updateCarInfo(carInfo));
    }

    /**
     * 删除汽车信息
     */
    @PreAuthorize("@ss.hasPermi('system:carinfo:remove')")
    @Log(title = "汽车信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carInfoService.deleteCarByIds(ids));
    }
}
